package com.wm.dao.hibernate;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import org.hibernate.Query;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bean.Person;

import com.wm.bean.Restaurant;
import com.wm.bean.User;
import com.wm.dao.RestaurantDao;
import com.wm.dao.UserDao;

@Transactional
public class UserDaoHibernate implements UserDao {
	@Resource
	private SessionFactory sessionFactory;
	private String hql;
	


	public User getUser(int userid) {
		String hql = "from User where uid = '"+ userid + "'";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		List<User> uList = query.list();
		System.out.println(uList.get(0).getName());
		return uList.get(0);
	}

	@Transactional
	public void save(User user) {
		sessionFactory.getCurrentSession().persist(user);

	}
	

	public List<User> getUserByName(String name) {
		String hql = "from User where name = '"+ name + "'";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		List<User> uList = query.list();
//		System.out.println(uList.get(0).getName());
		return uList;
	}

	
	public List<User> getUserByHql(String hql) {
		
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		List<User> uList = query.list();
//		System.out.println(uList.get(0).getName());
		return uList;

	}
	
	


}
